/**
 * Storage二次封装
 */
const PROJECT_NAME = 'sql_study'

export default {
  setItem(key: any, value: String) {
    let storage = this.getStorage()
    storage[key] = value
    window.localStorage.setItem(PROJECT_NAME, JSON.stringify(storage))
  },
  getItem(key: any) {
    return this.getStorage()[key]
  },
  getStorage() {
    return JSON.parse(window.localStorage.getItem(PROJECT_NAME) || '{}')
  },
  clearItem(key: any) {
    let storage = this.getStorage()
    delete storage[key]
    window.localStorage.setItem(PROJECT_NAME, JSON.parse(storage))
  },
  clearAll() {
    window.localStorage.setItem(PROJECT_NAME, '')
    window.localStorage.clear()
  }
}
